home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / util / httplib2 / iri2uri.pyo (.txt) < prev   
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  84 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. __author__ = 'Joe Gregorio (joe@bitworking.org)'
  5. __copyright__ = 'Copyright 2006, Joe Gregorio'
  6. __contributors__ = []
  7. __version__ = '1.0.0'
  8. __license__ = 'MIT'
  9. __history__ = '\n'
  10. import urlparse
  11. escape_range = [
  12.     (160, 55295),
  13.     (57344, 63743),
  14.     (63744, 64975),
  15.     (65008, 65519),
  16.     (65536, 131069),
  17.     (131072, 196605),
  18.     (196608, 262141),
  19.     (262144, 327677),
  20.     (327680, 393213),
  21.     (393216, 458749),
  22.     (458752, 524285),
  23.     (524288, 589821),
  24.     (589824, 655357),
  25.     (655360, 720893),
  26.     (720896, 786429),
  27.     (786432, 851965),
  28.     (851968, 917501),
  29.     (921600, 983037),
  30.     (983040, 1048573),
  31.     (1048576, 1114109)]
  32.  
  33. def encode(c):
  34.     retval = c
  35.     i = ord(c)
  36.     for low, high in escape_range:
  37.         if i < low:
  38.             break
  39.         
  40.         if i >= low and i <= high:
  41.             retval = []([ '%%%2X' % ord(o) for o in c.encode('utf-8') ])
  42.             break
  43.             continue
  44.         []
  45.     
  46.     return retval
  47.  
  48.  
  49. def iri2uri(uri):
  50.     return uri
  51.  
  52. if __name__ == '__main__':
  53.     import unittest
  54.     
  55.     class Test(unittest.TestCase):
  56.         
  57.         def test_uris(self):
  58.             invariant = [
  59.                 u'ftp://ftp.is.co.za/rfc/rfc1808.txt',
  60.                 u'http://www.ietf.org/rfc/rfc2396.txt',
  61.                 u'ldap://[2001:db8::7]/c=GB?objectClass?one',
  62.                 u'mailto:John.Doe@example.com',
  63.                 u'news:comp.infosystems.www.servers.unix',
  64.                 u'tel:+1-816-555-1212',
  65.                 u'telnet://192.0.2.16:80/',
  66.                 u'urn:oasis:names:specification:docbook:dtd:xml:4.1.2']
  67.             for uri in invariant:
  68.                 self.assertEqual(uri, iri2uri(uri))
  69.             
  70.  
  71.         
  72.         def test_iri(self):
  73.             self.assertEqual('http://xn--o3h.com/%E2%98%84', iri2uri(u'http://\xe2\x98\x84.com/\xe2\x98\x84'))
  74.             self.assertEqual('http://bitworking.org/?fred=%E2%98%84', iri2uri(u'http://bitworking.org/?fred=\xe2\x98\x84'))
  75.             self.assertEqual('http://bitworking.org/#%E2%98%84', iri2uri(u'http://bitworking.org/#\xe2\x98\x84'))
  76.             self.assertEqual('#%E2%98%84', iri2uri(u'#\xe2\x98\x84'))
  77.             self.assertEqual('/fred?bar=%E2%98%9A#%E2%98%84', iri2uri(u'/fred?bar=\xe2\x98\x9a#\xe2\x98\x84'))
  78.             self.assertEqual('/fred?bar=%E2%98%9A#%E2%98%84', iri2uri(iri2uri(u'/fred?bar=\xe2\x98\x9a#\xe2\x98\x84')))
  79.             self.assertNotEqual('/fred?bar=%E2%98%9A#%E2%98%84', iri2uri(u'/fred?bar=\xe2\x98\x9a#\xe2\x98\x84'.encode('utf-8')))
  80.  
  81.  
  82.     unittest.main()
  83.  
  84.